<template>
  <div class="app-container">
    新建账户
    <el-form ref="ruleForm" :model="ruleForm" :rules="rules" label-width="100px" class="demo-ruleForm">
      <el-form-item label="id" prop="id">
        <el-input v-model="ruleForm.id" />
      </el-form-item>

      <el-form-item label="名称" prop="name">
        <el-input v-model="ruleForm.name" />
      </el-form-item>
      <el-form-item label="平台">
        <el-select v-model="ruleForm.PlatformSign">
          <el-option label="币安USDT" value="Binance_USDT" />
          <el-option label="币安USD" value="Binance_USD" />
        </el-select>
      </el-form-item>
      <el-form-item label="AccessKey" prop="AccessKey">
        <el-input v-model="ruleForm.AccessKey" />
      </el-form-item>
      <el-form-item label="SecretKey" prop="SecretKey">
        <el-input v-model="ruleForm.SecretKey" />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import exchangeApi from '@/api/exchange'
export default {
  data() {
    return {
      loading: false,
      ruleForm: { // name, ExchangeId,Pair,strategyId,StrategyArgs
        name: '',
        id: '',
        PlatformSign: 'Binance_USDT',
        AccessKey: '',
        SecretKey: ''
      },
      rules: {
        name: [
          { required: true, message: '请输入名称', trigger: 'blur' },
          { min: 3, max: 15, message: '长度在 3 到 15 个字符', trigger: 'blur' }
        ],
        id: [
          { required: true, message: '请输入id', trigger: 'blur' },
          { min: 3, max: 15, message: '长度在 3 到 15 个字符', trigger: 'blur' }
        ],
        AccessKey: [
          { required: true, message: 'AccessKey', trigger: 'blur' },
          { min: 3, max: 100, message: '长度在 3 到 100 个字符', trigger: 'blur' }
        ],
        SecretKey: [
          { required: true, message: 'SecretKey', trigger: 'blur' },
          { min: 3, max: 100, message: '长度在 3 到 100 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
  },
  mounted() {

  },
  methods: {

    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          exchangeApi.add(this.ruleForm).then(p => {
            this.$alert('添加完毕')
          })
        } else {
          return false
        }
      })
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style scoped>
.line {
  text-align: center;
}
</style>

